package com.prg.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-10-26
 * Time: 下午1:10
 * To change this template use File | Settings | File Templates.
 */
public class HibernateUtil {
    private static SessionFactory factory;
    static {
        Configuration cfg=new Configuration().configure();
        factory=cfg.buildSessionFactory();
    }
    public static SessionFactory getSessionFactory(){
        return factory;
    }
    public  static Session getSession(){
        return factory.openSession();
    }
    public static void closeSession(Session session){
        if (session!=null){
            if (session.isOpen()){
                session.close();
            }
        }

    }
}
